package com.sls.game.dao.wogreat.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.dao.wogreat.WogreatRechargeDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.wogreat.WogreatRechargeType;

@Repository("wogreatRechargeDAO")
public class WogreatRechargeDAOImpl extends SuperDAO<WogreatRechargeType>
		implements WogreatRechargeDAO {

	@Override
	public void insertRecharge(WogreatRechargeType recharge) {
		this.getSqlSession().insert(
				"mybatis.xml.WogreatRechargeTypeMapper.insert", recharge);

	}

	@Override
	public List<WogreatRechargeType> queryByProIdAndRechargeName(
			WogreatRechargeType recharge) {
		return this
				.getSqlSession()
				.selectList(
						"mybatis.xml.WogreatRechargeTypeMapper.queryByProIdAndRechargeName",
						recharge);
	}

	@Override
	public Pagination<WogreatRechargeType> queryPage(
			WogreatRechargeType recharge) {
		Pagination<WogreatRechargeType> paginationList = null;
		Integer rowCount = queryRowCount(recharge);
		recharge.calculate();
		List<WogreatRechargeType> list = queryASList(recharge);
		paginationList = this.queryPagination(rowCount, list, recharge);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private Integer queryRowCount(WogreatRechargeType recharge) {
		Integer rowCount = this.getSqlSession()
				.selectOne(
						"mybatis.xml.WogreatRechargeTypeMapper.queryRowCount",
						recharge);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private List<WogreatRechargeType> queryASList(WogreatRechargeType recharge) {
		List<WogreatRechargeType> list = this
				.getSqlSession()
				.selectList(
						"mybatis.xml.WogreatRechargeTypeMapper.queryWogreatRechargeInfoList",
						recharge);
		return list;
	}

	@Override
	public List<String> queryRechargeNameByProductId(String productId) {
		List<String> list = this
				.getSqlSession()
				.selectList(
						"mybatis.xml.WogreatRechargeTypeMapper.queryRechargeNameByProductId",
						productId);
		return list;
	}

	@Override
	public void deleteByProductId(String productId) {
		this.getSqlSession().delete(
				"mybatis.xml.WogreatRechargeTypeMapper.deleteByProductId",
				productId);
	}

}
